Skip to main content

10. Penalty Point Calculation

Driver penalty points are recalculated only for the drivers queued in the penalty points calculation queue. This ensures that any changes to penalties—such as newly added penalties or expired penalties—are updated accurately in the driver's record.

Scheduler name: updateDriverPenaltyPoints


Overview

The penalty points calculation process ensures drivers' records are accurate by processing entries from the penalty points calculation queue. This queue contains records for specific drivers whose penalty points need to be recalculated based on two primary triggers:

  1. Successful DVLA Licence Check:
    After a successful DVLA licence check, the driver's record is added to the queue for the current date.

  2. Penalty End Date:
    For each penalty associated with the driver, an entry is added to the queue for the day the penalty ends.


Penalty Points Calculation Logic

When processing a driver's penalty points, the following logic determines which penalties are considered:

  1. Considered Penalties:

    • Penalties with no endDate (indicating an indefinite penalty).
    • Penalties with an endDate in the future.
    • Penalties whose endDate is today.
  2. Ignored Penalties:

    • Penalties with an endDate in the past (before today's date).
  3. Calculation Method:

    • Each valid penalty contributes to the total penalty points based on its penaltyPoints value.
    • The value is summed up only if:
      • It is a valid number (isNumber).
      • It is not NaN.
    • Invalid values are ignored during the summation process.

Example

Considering today's date is 2025-01-15 and the driver has the following penalties:

Penalties Data:

Penalty IDPenalty PointsEnd DateConsidered?
13NoneYes
222025-01-16Yes
352025-01-15Yes (today)
442025-01-14No (expired)

Total Penalty Points:
3 (Penalty 1) + 2 (Penalty 2) + 5 (Penalty 3) = 10


Updating Records

Once the penalty points are calculated, the following updates occur:

  1. Driver Record:
    The penaltyPoints and driverStat fields in the driver's record are updated with the new values.

  2. License Record:
    The penaltySeenByCustomer field is set to false, indicating that the customer has not yet reviewed the updated penalty information.

Status: Draft (Pending Review)
Category: Protected
Authored By: Sohan on Jan 15, 2025